package com.niit.drugsmanager.service.Impl;

import com.niit.drugsmanager.entity.Notice;
import com.niit.drugsmanager.repository.NoticeRepository;
import com.niit.drugsmanager.service.NoticeService;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Transactional
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeRepository noticeRepository;

    @Override
    public List<Notice> getAllNotice() {
        return noticeRepository.findAll();
    }

    @Override
    public void deleteNotice(Long id) {
        noticeRepository.deleteById(id);
    }

    @Override
    public Notice saveNotice(Notice notice) {
        return noticeRepository.save(notice);
    }

    @Override
    public @Nullable Notice getNoticeById(Long id) {
        return noticeRepository.findById(id).orElse(null);
    }
}
